﻿#include "alirtceventhandler.h"
#include "serialization.h"

AliRtcEventHandler::AliRtcEventHandler(QObject *inservice):service(inservice)
{
}

void AliRtcEventHandler::OnJoinChannelResult(int result, const char *channel, const char *userId, int elapsed) {
    qDebug() << "[RTC] OnJoinChannelResult - result:" << result << ", channel:" << channel << ", userId:" << userId << ", elapsed:" << elapsed;
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventJoinChannelResult, result, channel, userId, elapsed)));
}

void AliRtcEventHandler::OnLeaveChannelResult(int result, ding::rtc::RtcEngineStats stats) {
    qDebug() << "[RTC] OnLeaveChannelResult - result:" << result;
    QString statsJson = sToJSONString<const ding::rtc::RtcEngineStats&>(stats, sRtcEngineStats);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventLeaveChannelResult, result, statsJson)));
}

void AliRtcEventHandler::OnRemoteUserOnLineNotify(const char* uid, int elapsed) {
    qDebug() << "[RTC] OnRemoteUserOnLineNotify - uid:" << uid << ", elapsed:" << elapsed;
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventRemoteUserOnLineNotify, uid, elapsed)));
}

void AliRtcEventHandler::OnRemoteUserOffLineNotify(const char* uid, ding::rtc::RtcEngineUserOfflineReason reason) {
    qDebug() << "[RTC] OnRemoteUserOffLineNotify - uid:" << uid << ", reason:" << reason;
    QString reasonJson = sToJSONStringEnum(reason, sRtcEngineUserOfflineReason);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventRemoteUserOffLineNotify, uid, reasonJson)));
}

void AliRtcEventHandler::OnBye(RtcEngineOnByeType code) {
    qDebug() << "[RTC] OnBye - code:" << code;
    QString codeJson = sToJSONStringEnum(code, sRtcEngineOnByeType);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventBye, codeJson)));
}

void AliRtcEventHandler::OnOccurError(int error, const char* msg) {
    qDebug() << "[RTC] OnOccurError - error:" << error << ", msg:" << msg;
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventOccurError, error, msg)));
}

void AliRtcEventHandler::OnRemoteTrackAvailableNotify(const char* uid, ding::rtc::RtcEngineAudioTrack audioTrack, ding::rtc::RtcEngineVideoTrack videoTrack) {
    qDebug() << "[RTC] OnRemoteTrackAvailableNotify - uid:" << uid << ", audioTrack:" << audioTrack << ", videoTrack:" << videoTrack;
    QString audioTrackJson = sToJSONStringEnum(audioTrack, sRtcEngineAudioTrack);
    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventRemoteTrackAvailableNotify, QString::fromUtf8(uid), audioTrackJson, videoTrackJson)));
}

void AliRtcEventHandler::OnFirstRemoteVideoFrameDrawn(const char* uid, ding::rtc::RtcEngineVideoTrack videoTrack, int width, int height, int elapsed) {
    qDebug() << "[RTC] OnFirstRemoteVideoFrameDrawn - uid:" << uid << ", videoTrack:" << videoTrack << ", width:" << width << ", height:" << height << ", elapsed:" << elapsed;
    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventFirstRemoteVideoFrameDrawn, QString::fromUtf8(uid), videoTrackJson, width, height, elapsed)));
}

void AliRtcEventHandler::OnFirstVideoPacketSend(ding::rtc::RtcEngineVideoTrack videoTrack, int timeCost) {
    qDebug() << "[RTC] OnFirstVideoPacketSend - videoTrack:" << videoTrack << ", timeCost:" << timeCost;
    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventFirstVideoPacketSend, videoTrackJson, timeCost)));
}

void AliRtcEventHandler::OnFirstVideoPacketReceived(const char* uid, ding::rtc::RtcEngineVideoTrack videoTrack, int timeCost) {
    qDebug() << "[RTC] OnFirstVideoPacketReceived - uid:" << uid << ", videoTrack:" << videoTrack << ", timeCost:" << timeCost;
    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventFirstVideoPacketReceived, QString::fromUtf8(uid), videoTrackJson, timeCost)));
}

void AliRtcEventHandler::OnFirstAudioPacketSend(int timeCost) {
    qDebug() << "[RTC] OnFirstAudioPacketSend - timeCost:" << timeCost;
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventFirstAudioPacketSend, timeCost)));
}

void AliRtcEventHandler::OnFirstAudioPacketReceived(const char* uid, int timeCost) {
    qDebug() << "[RTC] OnFirstAudioPacketReceived - uid:" << uid << ", timeCost:" << timeCost;
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventFirstAudioPacketReceived, QString::fromUtf8(uid), timeCost)));
}

void AliRtcEventHandler::OnAudioSubscribeStateChanged(const char* uid, ding::rtc::RtcEngineSubscribeState oldState, ding::rtc::RtcEngineSubscribeState newState, int elapseSinceLastState, const char* channel) {
    qDebug() << "[RTC] OnAudioSubscribeStateChanged - uid:" << uid << ", oldState:" << oldState << ", newState:" << newState << ", elapseSinceLastState:" << elapseSinceLastState << ", channel:" << channel;
    QString oldStateJson = sToJSONStringEnum(oldState, sRtcEngineSubscribeState);
    QString newStateJson = sToJSONStringEnum(newState, sRtcEngineSubscribeState);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventAudioSubscribeStateChanged, QString::fromUtf8(uid), oldStateJson, newStateJson, elapseSinceLastState, QString::fromUtf8(channel))));
}

void AliRtcEventHandler::OnVideoSubscribeStateChanged(const char* uid, ding::rtc::RtcEngineSubscribeState oldState, ding::rtc::RtcEngineSubscribeState newState, int elapseSinceLastState, const char* channel) {
    qDebug() << "[RTC] OnVideoSubscribeStateChanged - uid:" << uid << ", oldState:" << oldState << ", newState:" << newState << ", elapseSinceLastState:" << elapseSinceLastState << ", channel:" << channel;
    QString oldStateJson = sToJSONStringEnum(oldState, sRtcEngineSubscribeState);
    QString newStateJson = sToJSONStringEnum(newState, sRtcEngineSubscribeState);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventVideoSubscribeStateChanged, QString::fromUtf8(uid), oldStateJson, newStateJson, elapseSinceLastState, QString::fromUtf8(channel))));
}

void AliRtcEventHandler::OnRecordingDeviceAudioLevel(int level) {
    qDebug() << "[RTC] OnRecordingDeviceAudioLevel - level:" << level;
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventRecordingDeviceAudioLevel, level)));
}

void AliRtcEventHandler::OnAudioDeviceStateChanged(const char* deviceId, ding::rtc::RtcEngineDeviceType deviceType, ding::rtc::RtcEngineDeviceState deviceState) {
    qDebug() << "[RTC] OnAudioDeviceStateChanged - deviceId:" << deviceId << ", deviceType:" << deviceType << ", deviceState:" << deviceState;
    QString deviceTypeJson = sToJSONStringEnum(deviceType, sRtcEngineDeviceType);
    QString deviceStateJson = sToJSONStringEnum(deviceState, sRtcEngineDeviceState);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventAudioDeviceStateChanged, QString::fromUtf8(deviceId), deviceTypeJson, deviceStateJson)));
}

void AliRtcEventHandler::OnVideoDeviceStateChanged(const char* deviceId, ding::rtc::RtcEngineDeviceType deviceType, ding::rtc::RtcEngineDeviceState deviceState) {
    qDebug() << "[RTC] OnVideoDeviceStateChanged - deviceId:" << deviceId << ", deviceType:" << deviceType << ", deviceState:" << deviceState;
    QString deviceTypeJson = sToJSONStringEnum(deviceType, sRtcEngineDeviceType);
    QString deviceStateJson = sToJSONStringEnum(deviceState, sRtcEngineDeviceState);
    QMetaObject::invokeMethod(service, "processCallback", Q_ARG(RTCEngineCallback, t_packageCallback(AliRtcEvents::AliRtcEventVideoDeviceStateChanged, QString::fromUtf8(deviceId), deviceTypeJson, deviceStateJson)));
}

void AliRtcEventHandler::OnAudioPublishStateChanged(ding::rtc::RtcEnginePublishState oldState, ding::rtc::RtcEnginePublishState newState, int elapseSinceLastState, const char* channel) {
    qDebug() << "[RTC] OnAudioPublishStateChanged - oldState:" << oldState << ", newState:" << newState;
    QString oldStateJson = sToJSONStringEnum(oldState, sRtcEnginePublishState);
    QString newStateJson = sToJSONStringEnum(newState, sRtcEnginePublishState);
    QMetaObject::invokeMethod(service, "processCallback",
                              Q_ARG(RTCEngineCallback,
                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioPublishStateChanged, oldStateJson, newStateJson, elapseSinceLastState, channel)));
}

//void AliRtcEventHandler::OnVideoPublishStateChanged(ding::rtc::RtcEnginePublishState oldState, ding::rtc::RtcEnginePublishState newState, int elapseSinceLastState, const char* channel) {
//    QString oldStateJson = sToJSONStringEnum(oldState, sRtcEnginePublishState);
//    QString newStateJson = sToJSONStringEnum(newState, sRtcEnginePublishState);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventVideoPublishStateChanged, oldStateJson, newStateJson, elapseSinceLastState, QString::fromUtf8(channel))));
//}
//void AliRtcEventHandler::OnChannelRemainingTimeNotify(int remainingTimeInSec) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventChannelRemainingTimeNotify, remainingTimeInSec)));
//}

//void AliRtcEventHandler::OnConnectionStatusChanged(ding::rtc::RtcEngineConnectionStatus status, ding::rtc::RtcEngineConnectionStatusChangeReason reason) {
//    QString statusJson = sToJSONStringEnum(status, sRtcEngineConnectionStatus);
//    QString reasonJson = sToJSONStringEnum(reason, sRtcEngineConnectionStatusChangeReason);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventConnectionStatusChanged, statusJson, reasonJson)));
//}

//void AliRtcEventHandler::OnNetworkQualityChanged(const char* uid, ding::rtc::RtcEngineNetworkQuality upQuality, ding::rtc::RtcEngineNetworkQuality downQuality) {
//    QString upQualityJson = sToJSONStringEnum(upQuality, sRtcEngineNetworkQuality);
//    QString downQualityJson = sToJSONStringEnum(downQuality, sRtcEngineNetworkQuality);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventNetworkQualityChanged, uid, upQualityJson, downQualityJson)));
//}

//void AliRtcEventHandler::OnStatisticsLog(String const& log) {


//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventStatisticsLog, QString::fromStdString(log.c_str()))));
//}

//void AliRtcEventHandler::OnOccurWarning(int warn, const char* msg) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventOccurWarning, warn, msg)));
//}

//void AliRtcEventHandler::OnStatisticsLevelLog(int level, const String& log) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventStatisticsLevelLog, level, QString::fromStdString(log.c_str()))));
//}

//void AliRtcEventHandler::OnQualityReport(const ding::rtc::QualityReport& quality) {
//    QString qualityJson = sToJSONString<const ding::rtc::QualityReport&>(quality, sQualityReport);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventQualityReport, qualityJson)));
//}

//void AliRtcEventHandler::OnLocalAudioStats(const ding::rtc::LocalAudioStats& localAudioStats) {

//    qDebug() << "OnLocalAudioStats - localAudioStats.track:" << localAudioStats.track;
//    QString audioStatsJson = sToJSONString<const ding::rtc::LocalAudioStats&>(localAudioStats, sLocalAudioStats);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventLocalAudioStats, audioStatsJson)));
//}

//void AliRtcEventHandler::OnLocalVideoStats(const ding::rtc::LocalVideoStats& localVideoStats) {
//    QString videoStatsJson = sToJSONString<const ding::rtc::LocalVideoStats&>(localVideoStats, sLocalVideoStats);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventLocalVideoStats, videoStatsJson)));
//}

//void AliRtcEventHandler::OnRemoteAudioStats(const ding::rtc::RemoteAudioStats& remoteAudioStats) {
//    QString remoteAudioStatsJson = sToJSONString<const ding::rtc::RemoteAudioStats&>(remoteAudioStats, sRemoteAudioStats);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventRemoteAudioStats, remoteAudioStatsJson)));
//}

//void AliRtcEventHandler::OnRemoteVideoStats(const ding::rtc::RemoteVideoStats& remoteVideoStats) {
//    QString remoteVideoStatsJson = sToJSONString<const ding::rtc::RemoteVideoStats&>(remoteVideoStats, sRemoteVideoStats);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventRemoteVideoStats, remoteVideoStatsJson)));
//}

//void AliRtcEventHandler::OnStats(const ding::rtc::RtcEngineStats& stats) {
//    QString statsJson = sToJSONString<const ding::rtc::RtcEngineStats&>(stats, sRtcEngineStats);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventStats, statsJson)));
//}

//void AliRtcEventHandler::OnScreenSharePublishStateChanged(ding::rtc::RtcEnginePublishState oldState, ding::rtc::RtcEnginePublishState newState, int elapseSinceLastState, const char* channel) {
//    QString oldStateJson = sToJSONStringEnum(oldState, sRtcEnginePublishState);
//    QString newStateJson = sToJSONStringEnum(newState, sRtcEnginePublishState);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventScreenSharePublishStateChanged, oldStateJson, newStateJson, elapseSinceLastState, QString::fromUtf8(channel))));
//}

//void AliRtcEventHandler::OnUserAudioMuted(const char* uid, bool isMute) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventUserAudioMuted, QString::fromUtf8(uid), isMute)));
//}

//void AliRtcEventHandler::OnUserVideoMuted(const char* uid, bool isMute, ding::rtc::RtcEngineVideoTrack videoTrack) {
//    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventUserVideoMuted, QString::fromUtf8(uid), isMute, videoTrackJson)));
//}

//void AliRtcEventHandler::OnUserVideoEnabled(const char* uid, bool enabled) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventUserVideoEnabled, QString::fromUtf8(uid), enabled)));
//}

//void AliRtcEventHandler::OnUserWillResignActive(const char* uid) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventUserWillResignActive, QString::fromUtf8(uid))));
//}

//void AliRtcEventHandler::OnUserWillBecomeActive(const char* uid) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventUserWillBecomeActive, QString::fromUtf8(uid))));
//}

//void AliRtcEventHandler::OnFirstLocalVideoFrameDrawn(int width, int height, int elapsed) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventFirstLocalVideoFrameDrawn, width, height, elapsed)));
//}

//void AliRtcEventHandler::OnFirstVideoFrameReceived(const char* uid, ding::rtc::RtcEngineVideoTrack videoTrack, int timeCost) {
//    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventFirstVideoFrameReceived, QString::fromUtf8(uid), videoTrackJson, timeCost)));
//}


//void AliRtcEventHandler::OnRenderRemoteVideoSizeChanged(const char* uid, ding::rtc::RtcEngineVideoTrack videoTrack, int newWidth, int newHeight, int oldWidth, int oldHeight) {
//    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventRenderRemoteVideoSizeChanged, QString::fromUtf8(uid), videoTrackJson, newWidth, newHeight, oldWidth, oldHeight)));
//}

//void AliRtcEventHandler::OnRenderLocalVideoSizeChanged(ding::rtc::RtcEngineVideoTrack videoTrack, int newWidth, int newHeight, int oldWidth, int oldHeight) {
//    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventRenderLocalVideoSizeChanged, videoTrackJson, newWidth, newHeight, oldWidth, oldHeight)));
//}

//void AliRtcEventHandler::OnScreenShareSubscribeStateChanged(const char* uid, ding::rtc::RtcEngineSubscribeState oldState, ding::rtc::RtcEngineSubscribeState newState, int elapseSinceLastState, const char* channel) {
//    QString oldStateJson = sToJSONStringEnum(oldState, sRtcEngineSubscribeState);
//    QString newStateJson = sToJSONStringEnum(newState, sRtcEngineSubscribeState);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventScreenShareSubscribeStateChanged,
//                                                      QString::fromUtf8(uid), oldStateJson, newStateJson, elapseSinceLastState, QString::fromUtf8(channel))));
//}

//void AliRtcEventHandler::OnSubscribeStreamTypeChanged(const char* uid, ding::rtc::RtcEngineVideoStreamType oldStreamType, ding::rtc::RtcEngineVideoStreamType newStreamType, int elapseSinceLastState, const char* channel) {
//    QString oldStreamTypeJson = sToJSONStringEnum(oldStreamType, sRtcEngineVideoStreamType);
//    QString newStreamTypeJson = sToJSONStringEnum(newStreamType, sRtcEngineVideoStreamType);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventSubscribeStreamTypeChanged,
//                                                      QString::fromUtf8(uid), oldStreamTypeJson, newStreamTypeJson, elapseSinceLastState, QString::fromUtf8(channel))));
//}



//void AliRtcEventHandler::OnPlayoutDeviceAudioLevel(int level) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventPlayoutDeviceAudioLevel, level)));
//}

//void AliRtcEventHandler::OnAudioVolumeIndication(const ding::rtc::AudioVolumeInfo* speakers, unsigned int speakerNumber) {
//    // 将 speakers 转换为 std::vector<AudioVolumeInfo>
//    std::vector<AudioVolumeInfo> speakerList;
//    for (unsigned int i = 0; i < speakerNumber; ++i) {
//        speakerList.push_back(speakers[i]); // 添加到 vector 中
//    }

//    QString speakerJson = sToJSONString<const std::vector<AudioVolumeInfo>&>(speakerList,sAudioVolumeInfoList);


//    // 调用回调函数，将序列化后的 JSON 对象作为参数
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioVolumeIndication, speakerJson,speakerNumber)));
//}

//void AliRtcEventHandler::OnApiCalledExecuted(int error, const char* api, const char* result) {
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventApiCalledExecuted, error, QString::fromUtf8(api), QString::fromUtf8(result))));
//}

//void AliRtcEventHandler::OnSnapshotComplete(const char* userId, ding::rtc::RtcEngineVideoTrack videoTrack, const char* filePath, int width, int height, bool success) {
//    QString videoTrackJson = sToJSONStringEnum(videoTrack, sRtcEngineVideoTrack);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventSnapshotComplete,
//                                                      QString::fromUtf8(userId), videoTrackJson, QString::fromUtf8(filePath), width, height, success)));
//}

//void AliRtcEventHandler::OnMediaExtensionMsgReceived(const char* uid, unsigned char* message, unsigned int size) {
//    QString messageStr = QString::fromUtf8(reinterpret_cast<char*>(message), size);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventMediaExtensionMsgReceived,
//                                                      QString::fromUtf8(uid), messageStr)));
//}

//void AliRtcEventHandler::OnAudioMixingStateChanged(const RtcEngineAudioMixingStatusConfig& status) {
//    QString statusJson = sToJSONString<const ding::rtc::RtcEngineAudioMixingStatusConfig&>(status, sRtcEngineAudioMixingStatusConfig);
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioMixingStateChanged, statusJson)));
//}

//void AliRtcEventHandler::OnListAllAudioGroups(const ding::rtc::StringArray& groups) {
//    // 创建一个 QStringList，并将 StringArray 转换为 QStringList
//    QStringList groupList;
//    for (size_t i = 0; i < groups.size(); ++i) {
//        groupList.append(QString::fromUtf8(groups.at(i).c_str()));  // 使用 get(i) 或其他访问方法
//    }

//    // 调用回调函数，传递转换后的 QStringList
//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventListAllAudioGroups, groupList)));
//}

//void AliRtcEventHandler::OnAudioGroupJoinResult(int result, const ding::rtc::String& errMsg, const ding::rtc::String& group, RtcEngineAudioGroupMember* members, int memberCount) {
//    QString errMsgStr = QString::fromUtf8(errMsg.c_str());
//    QString groupStr = QString::fromUtf8(group.c_str());

//    // 序列化成员列表
//    QJsonArray memberArray;
//    for (int i = 0; i < memberCount; ++i) {
//        QJsonObject memberJson = sRtcEngineAudioGroupMember(members[i]);
//        memberArray.append(memberJson);
//    }

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupJoinResult, result, errMsgStr, groupStr, memberArray)));
//}

//void AliRtcEventHandler::OnAudioGroupLeaveResult(int result, const ding::rtc::String& errMsg, const ding::rtc::String& group) {
//    QString errMsgStr = QString::fromUtf8(errMsg.c_str());
//    QString groupStr = QString::fromUtf8(group.c_str());

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupLeaveResult, result, errMsgStr, groupStr)));
//}

//void AliRtcEventHandler::OnAudioGroupDismissResult(int result, const ding::rtc::String& errMsg, const ding::rtc::String& group) {
//    QString errMsgStr = QString::fromUtf8(errMsg.c_str());
//    QString groupStr = QString::fromUtf8(group.c_str());

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupDismissResult, result, errMsgStr, groupStr)));
//}

//void AliRtcEventHandler::OnAudioGroupMixResult(const ding::rtc::String& group, bool mix, int result, const ding::rtc::String& reason) {
//    QString groupStr = QString::fromUtf8(group.c_str());
//    QString reasonStr = QString::fromUtf8(reason.c_str());

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupMixResult, groupStr, mix, result, reasonStr)));
//}

//void AliRtcEventHandler::OnAudioGroupMemberUpdate(int update_opt, const ding::rtc::String& group, RtcEngineAudioGroupMember* members, int memberCount) {
//    QString groupStr = QString::fromUtf8(group.c_str());

//    // 序列化成员列表
//    QJsonArray memberArray;
//    for (int i = 0; i < memberCount; ++i) {
//        QJsonObject memberJson = sRtcEngineAudioGroupMember(members[i]);
//        memberArray.append(memberJson);
//    }

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupMemberUpdate, update_opt, groupStr, memberArray)));
//}

//void AliRtcEventHandler::OnAudioGroupHallMembers(RtcEngineAudioGroupMember* hallMembers, int hallMemberCount) {
//    // 序列化大厅成员列表
//    QJsonArray hallMemberArray;
//    for (int i = 0; i < hallMemberCount; ++i) {
//        QJsonObject memberJson = sRtcEngineAudioGroupMember(hallMembers[i]);
//        hallMemberArray.append(memberJson);
//    }

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupHallMembers, hallMemberArray)));
//}

//void AliRtcEventHandler::OnAudioGroupListUpdate(int update_opt, const ding::rtc::String& group) {
//    QString groupStr = QString::fromUtf8(group.c_str());

//    QMetaObject::invokeMethod(service, "processCallback",
//                              Q_ARG(RTCEngineCallback,
//                                    t_packageCallback(AliRtcEvents::AliRtcEventAudioGroupListUpdate, update_opt, groupStr)));
//}

template<typename... Args>
RTCEngineCallback AliRtcEventHandler::t_packageCallback(AliRtcEvents::AliRtcCallbackEvent event,Args... args)
{
    QVector<QVariant> params;
    appendParams(params, args...);

    return RTCEngineCallback(event, params);
}

